global infile "DataMain.dta"
global outfile "$results\Figure 4"


* Inputs

scalar pre = 99.29
scalar effect = -17.77
scalar pos = pre + effect
scalar p1 = 0
scalar p2 = 0.09
scalar Q1 = pre
scalar Q2 = pre + effect


* Computation - Demand curve

scalar slope = (p2-p1)/(Q2-Q1)
scalar intercept = -(slope)*pre
scalar dwl = (effect * p2)/2


* Results

display slope                  
display intercept        
display dwl              
display Q2               


* Figure 4. DWL

clear
set obs 10000                                    
gen x = (_n-1)/100
gen D = intercept + slope * x
gen S = 0.09
gen y0 = 0
drop if x > pre
scalar b = Q2 + 100                       	 /* to adjust border of B area*/
global pre = pre
global pos = pos

twoway (rarea D S x if x<= Q2,color(white%50) lcolor(black) lpattern(dash)) ///
(rarea D S x if x>= Q2, color(gs10%50) lcolor(black) lpattern(dash)) ///
(rarea y0 S x if x<= b,color(white%50) lcolor(black) lpattern(dash)) ///
(rarea y0 D x if x>= Q2,color(white%50) lcolor(black) lpattern(dash)) ///
(line D S x, lcolor(navy maroon) lwidth(thick medium)) ///
(scatteri 0.09 $pos (1) "With IMB", mcolor(dark) mlabcolor(dark)) ///
(scatteri 0 $pre (2) "Without IMB", mcolor(dark) mlabcolor(dark)), ///
legend(order(5 "Demand" 6 "Supply") region(lstyle(none) lcolor(white))) ///
text(0.25 20 "A", place(e) color(black)) ///
text(0.05 40 "B", place(e) color(black)) ///
text(0.035 85 "C", place(e) color(black)) ///
text(0.06 90 "DWL", place(e) color(black)) ///
text(0.12 40 "Supply", color(maroon)) ///
text(0.38 40 "Demand", color(navy)) ///
xlabel(,labs(small)) xtitle("Hot water consumption (l/day)",size(small)) ///
ylabel(,labs(small)) ytitle("Price (SEK/l)", size(small)) graphregion(color(white)) ///
xsc(r(0 120)) leg(off)

graph save "$outfile", replace
